// ActionScript file
package
{
        import flash.display.Sprite;
        import flash.events.Event;

        import parts.Particle1;

        [SWF(backgroundColor="#333333", frameRate="30", width="300", height="300")]
        public class PlayingWithParticlesExample1 extends Sprite
        {
                private const PARTICLE_NUMBER:uint = 3125;
                private var particles:Array;

                public function PlayingWithParticlesExample1()
                {
                        super();
                        init();
                }

                private function init():void
                {
                        //somewhere to store a reference to the particles
                        particles = [];
                        //create particles
                        for (var i:uint=0;i<PARTICLE_NUMBER;i++)
                        {
                                //create a particle with random position and velocity
                                var p:Particle1 = new Particle1();
                                //add particle to stage
                                addChild(p);
                                
                                //store reference to particle for later
                                particles.push(p);
                        }
                        //start looping
                        addEventListener(Event.ENTER_FRAME, loop);
                }

                private function loop(event:Event):void
                {
                        //loop through the particles
                        for (var i:uint=0;i<PARTICLE_NUMBER;i++)
                        {
                                //tell each particle to update itself
                                particles[i].update();
                        }
                }

        }
}